1. Field of the Invention
This application relates to the field of software and more particularly to the field of providing accurate profile and timing information for software that is executed in connection with an operating system that automatically shares processor resources with multiple portions of software.
2. Description of Related Art
A profiler is a software development tool used to determine execution time for a program or for a particular portion(s) of a program. The profiler may be used for optimizing code by providing a developer with execution time information for various blocks thereof. The developer uses this information to modify portions of code that can then be rerun using the profiler to confirm that the modifications have shortened the execution time.
A common technique for profiling a block of code is to record a first timestamp immediately prior to execution of the block of code and to record a second timestamp immediately following execution of the block of code. The difference between the first and second timestamps is the amount of time used for executing the block of code. In some instances, the timestamps can be provided by accessing a system clock of the computer system.
In multitasking operating systems, multiple blocks of code share processor time. Swapping of tasks is performed by an operating system that causes the various blocks of code to have access to the processor, one at a time. This swapping is often performed in a way that is transparent to the blocks of code. That is, each of the blocks of code is swapped in and swapped out in a manner that is not detected by the block of code. In addition, in many instances, the swapping may be performed during execution of any portion of the block of code.
A multitasking operating system provides challenges to profiling a block of code. Specifically, using the timestamp technique described above would create inaccuracy since the difference between the first and second timestamp values would not necessarily be the time spent executing of the block of code. In some instances, the block of code may have been swapped out by the operating system after the first timestamp value is recorded but before the second timestamp value is recorded. Thus, the difference between the timestamp values would be the sum of the execution time of the block of code plus an indeterminate amount of time that the block of code spent being swapped out while other, unrelated, blocks of code had access to the processor.
One solution to this difficulty is to calculate profiling information based on an expected execution time of the block of code. The expected execution time may be determined using the individual execution times of each of the instructions that make up the block of code. However, there are a number of difficulties with this technique. In the first place, the same code may run on different processors of the same family that have different execution times for the same instructions. Similarly, the same processor may run under different clock speeds. Thus, a particular instruction for a processor family may not have one particular value for execution time. In addition, some processors employ instruction caching in which groups of instructions are executed more quickly than the sum of execution times of each of the individual instructions. Caching is accomplished via a variety of conventional techniques, such as pipelining and using internal memory having a shorter access time than the external RAM.
It would be advantageous to provide a reliable technique for profiling blocks of code that run in a multitasking system.